


<template>
  <div>
      <MyHead title="定位位置"></MyHead>
      <van-index-bar :index-list="indexList">
        <div v-for="(item,index) in indexList" :key="index">
          <van-index-anchor :index="index">{{ item }}</van-index-anchor>
          <van-cell @click="chooseCity(v)"
           v-for="(v,i) in city.filter((val)=> val.pinyin.indexOf(item.toLowerCase())==0 ) "  :title="v.name" />
        </div>
      </van-index-bar>
  </div>
</template>

<script>

export default {
  data(){
    return {
      city:[],
      indexList:[]
    }
  },
  methods:{
    chooseCity(v){
      console.log(v)  // vuex
      this.$router.go(-1)
    },
    async getCityData(){
        let res = await this.$axios.get('https://lhx123.love:3333/app/maizuo',{
          params:{

          },
          headers:{
            'X-Host':'mall.film-ticket.city.list'
          }
        })
        console.log(res)
        this.city = res.data.data.cities;
    }
  },
  mounted(){
    this.getCityData()

    for (let i = 'A'.charCodeAt(0); i <= 'Z'.charCodeAt(0); i++) {
        const letter = String.fromCharCode(i) ; // 将ASCII值转换为对应的字符并添加"S"
        this.indexList.push(letter)
    }
  }
}
</script>
